#include "MySqlConnPool.h"
#include "AsyncProcessor.h"
#include <cppconn/resultset.h>
#include <thread>
#include <chrono>

// 编译命令：g++ *.cpp -o main -lpthread -lmysqlcppconn -std=c++17
void HandleQueryResult(std::unique_ptr<sql::ResultSet> res)
{
    while (res->next())
    {
        std::cout << "cid: " << res->getInt("cid") 
        << " caption: " << res->getString("caption") << std::endl;
    }
}

//断线重连，心跳检测机制等功能后续添加
int main() 
{
    MySqlConnPool *pool = MySqlConnPool::GetInstance("TestBase");
    pool->InitConnPool("tcp://127.0.0.1:3306;root;1234", 10);

    auto queryback = pool->PushQuery("select * from user;",HandleQueryResult);
    AsyncProcessor asyncpo;
    asyncpo.AddAsyncCallback(std::move(queryback));

    while (true)
    {
        asyncpo.SparkIfReadyA();
        std::this_thread::sleep_for(std::chrono::milliseconds(100));
    }
    

    return 0;
}